package com.pansoft.openplanet.fragment;

import android.content.Context;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.efounder.chat.utils.LXGlideImageLoader;
import com.pansoft.openplanet.R;
import com.pansoft.openplanet.bean.MyAirdropBean;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 我的空投场
 */
public class MyAirDropAdapter extends RecyclerView.Adapter<MyAirDropAdapter.ViewHolder> {

    private Context mContext;
    private final List<MyAirdropBean> mValues;
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public MyAirDropAdapter(Context mContext, List<MyAirdropBean> items) {
        mValues = items;
        this.mContext = mContext;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.assets_item_my_air_drop, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        MyAirdropBean airdropBean = mValues.get(position);
        LXGlideImageLoader.getInstance().displayImage(mContext, holder.ivIamge, airdropBean.getPicture());
        holder.tvAssetName.setText(airdropBean.getCoinName());
        holder.tvAssetBalance.setText(airdropBean.getTokenNumber() + "");
        holder.tvTeamName.setText(airdropBean.getOrganization());
        String time = simpleDateFormat.format(new Date(airdropBean.getTime()));
        holder.tvTime.setText(time);
    }

    @Override
    public int getItemCount() {
        return mValues.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        private ImageView ivIamge;
        private TextView tvAssetName;
        private TextView tvAssetBalance;
        private TextView tvTeamName;
        private TextView tvTime;


        public ViewHolder(View view) {
            super(view);
            ivIamge = (ImageView) view.findViewById(R.id.iv_iamge);
            tvAssetName = (TextView) view.findViewById(R.id.tv_asset_name);
            tvAssetBalance = (TextView) view.findViewById(R.id.tv_asset_balance);
            tvTeamName = (TextView) view.findViewById(R.id.tv_team_name);
            tvTime = (TextView) view.findViewById(R.id.tv_time);

        }


    }


}
